package com.angel.bo.file.controller;

import com.angel.bo.file.param.MultipartFileParam;
import com.angel.bo.file.service.FileService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author: Haibo.Mei [Haibo.Mei@ge.com]
 * @Description:
 * @Date: 11:24 2018/2/28 
 */
@RestController
@Slf4j
@RequestMapping("/file")
public class AngelFileController {

    @Autowired
    private FileService fileService;

    @RequestMapping(value = "/fileUpload")
    @ResponseBody
    @ApiOperation(value = "fileUpload")
    public ResponseEntity fileUpload(MultipartFileParam param, HttpServletRequest request){

        boolean isMultipart = ServletFileUpload.isMultipartContent(request);
        if (isMultipart) {
            return fileService.uploadFile(param);
        }else {
            return fileService.checkUploadedFile(param);
        }
    }

}
